/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.service.attach;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.unis.common.util.TemplateUtil;
import com.unis.common.util.TimeUtil;
import com.unis.dao.IDataSet4iBatis;
import com.unis.model.BaseModel;
import com.unis.model.attach.AttachCatalog;

/**
 * @author CSJ (email:raulcsj@163.com)
 * @since 2013-03-05
 */
@Service("attachcatalogService")
public class AttachCatalogServiceImpl implements AttachCatalogService {

    private IDataSet4iBatis iDataSet4iBatis;

    /****************************************
     * Insert a instace of AttachCatalog
     ****************************************/
    public void insert(AttachCatalog attachcatalog) throws Exception {
        attachcatalog.setCatalogId(TemplateUtil.genUUID());
        attachcatalog.setCreateTime(TimeUtil.getNow());
        iDataSet4iBatis.insert(attachcatalog);
    }

    /****************************************
     * Update a instace of AttachCatalog
     ****************************************/
    public void update(AttachCatalog attachcatalog) throws Exception {
        iDataSet4iBatis.update(attachcatalog);
    }

    /****************************************
     * Delete a instace of AttachCatalog
     ****************************************/
    public void delete(AttachCatalog attachcatalog) throws Exception {
        iDataSet4iBatis.delete(attachcatalog);
    }

    /****************************************
     * Insert instaces of SysUser
     ****************************************/
    public void batchInsert(AttachCatalog attachcatalog) throws Exception {
        throw new RuntimeException("Not yet implement!");
    }

    /****************************************
     * Delete instaces of SysUser
     ****************************************/
    public void batchDelete(AttachCatalog attachcatalog) throws Exception {
        String statementId = attachcatalog.getStatmentId();
        String mainId = attachcatalog.getId();
        String[] ids = mainId.split(",");
        List<BaseModel> attachcatalogList = new ArrayList<BaseModel>();
        for (String id : ids) {
            AttachCatalog model = new AttachCatalog();
            model.setStatmentId(statementId);
            model.setId(id.trim());
            attachcatalogList.add(model);
        }
        iDataSet4iBatis.batchDelete(attachcatalogList);
    }

    /****************************************
     * Query instaces of AttachCatalog
     ****************************************/
    public List<BaseModel> queryAsList(AttachCatalog attachcatalog) throws Exception {
        String queryListStatement = "";
        if (attachcatalog.isPaging()) {
            queryListStatement = attachcatalog.getStatmentId();
            attachcatalog.setStatmentId("AttachCatalog.queryRecordsCount");
            BaseModel baseModel = iDataSet4iBatis.queryAsObject(attachcatalog);
            attachcatalog.setTotalCount(baseModel.getTotalCount());
            attachcatalog.setStatmentId(queryListStatement);
        }
        return iDataSet4iBatis.queryAsList(attachcatalog);
    }

    /****************************************
     * Query a instaces of AttachCatalog
     ****************************************/
    public BaseModel queryAsObject(AttachCatalog attachcatalog) throws Exception {
        return iDataSet4iBatis.queryAsObject(attachcatalog);
    }

    @Resource
    public void setiDataSet4iBatis(IDataSet4iBatis iDataSet4iBatis) {
        this.iDataSet4iBatis = iDataSet4iBatis;
    }
}
